package drawer

import (
	"MetroBuilderGameJam/gameEngine/geom"
	"github.com/hajimehoshi/ebiten/v2"
	"github.com/hajimehoshi/ebiten/v2/vector"
	"image/color"
)

func (d *Drawer) FillArrowRight(screen *ebiten.Image, pivot geom.Point, offset geom.Vec2, size geom.Size, rotation geom.Radian, clr color.Color) (autoCollider geom.Collider) {
	path := vector.Path{}
	offset = offset.Add(d.applyAnchor(d.Offset.AsVec2().Add(pivot.AsVec2()), size))

	p1 := geom.NewVec2(offset.X-size.Width, offset.Y-size.Height).RotateAround(rotation, pivot.AsVec2()).ToVec2F32()
	p2 := geom.NewVec2(offset.X+size.Width, offset.Y-size.Height/4).RotateAround(rotation, pivot.AsVec2()).ToVec2F32()
	p3 := geom.NewVec2(offset.X-size.Width, offset.Y+size.Height).RotateAround(rotation, pivot.AsVec2()).ToVec2F32()
	path.MoveTo(p1.X, p1.Y)
	path.LineTo(p2.X, p2.Y)
	path.LineTo(p3.X, p3.Y)
	path.LineTo(p1.X, p1.Y)

	vs, is, op := d.preparePathToFill(path, clr)
	d.drawPath(screen, vs, is, op)

	autoCollider = geom.MakeTrianglesCollider(vs, is)

	return autoCollider
}

func (d *Drawer) FillSoftArrowRight(screen *ebiten.Image, pivot geom.Point, offset geom.Vec2, size geom.Size, rotation geom.Radian, clr color.Color) (autoCollider geom.Collider) {
	path := vector.Path{}
	offset = offset.Add(d.applyAnchor(d.Offset.AsVec2().Add(pivot.AsVec2()), size))

	p1 := geom.NewVec2(offset.X, offset.Y-size.Height).RotateAround(rotation, pivot.AsVec2()).ToVec2F32()
	p2 := geom.NewVec2(offset.X+size.Width*2/3, offset.Y-size.Height/4).RotateAround(rotation, pivot.AsVec2()).ToVec2F32()
	p3 := geom.NewVec2(offset.X+size.Width*2/3, offset.Y+size.Height/4).RotateAround(rotation, pivot.AsVec2()).ToVec2F32()
	p4 := geom.NewVec2(offset.X, offset.Y+size.Height).RotateAround(rotation, pivot.AsVec2()).ToVec2F32()
	path.MoveTo(p1.X, p1.Y)
	path.LineTo(p2.X, p2.Y)
	path.LineTo(p3.X, p3.Y)
	path.LineTo(p4.X, p4.Y)
	path.LineTo(p1.X, p1.Y)

	vs, is, op := d.preparePathToFill(path, clr)
	d.drawPath(screen, vs, is, op)

	autoCollider = geom.MakeTrianglesCollider(vs, is)

	return autoCollider
}

func (d *Drawer) FillRectangle(screen *ebiten.Image, pivot geom.Point, size geom.Size, rotation geom.Radian, clr color.Color) (autoCollider geom.Collider) {
	path := vector.Path{}

	p1, p2, p3, p4 := d.GetRectanglePoints(pivot, size, rotation)
	path.MoveTo(p1.X, p1.Y)
	path.LineTo(p2.X, p2.Y)
	path.LineTo(p3.X, p3.Y)
	path.LineTo(p4.X, p4.Y)
	path.LineTo(p1.X, p1.Y)

	vs, is, op := d.preparePathToFill(path, clr)
	d.drawPath(screen, vs, is, op)

	autoCollider = geom.MakeTrianglesCollider(vs, is)

	return autoCollider
}
func (d *Drawer) FillSimpleRectangle(screen *ebiten.Image, pivot geom.Point, size geom.Size, clr color.Color) (autoCollider geom.Collider) {
	path := vector.Path{}

	p := pivot.AsVec2().ToVec2F32()

	path.MoveTo(p.X, p.Y)
	path.LineTo(p.X+float32(size.Width), p.Y)
	path.LineTo(p.X+float32(size.Width), p.Y+float32(size.Height))
	path.LineTo(p.X, p.Y+float32(size.Height))
	path.LineTo(p.X, p.Y)

	vs, is, op := d.preparePathToFill(path, clr)
	d.drawPath(screen, vs, is, op)

	autoCollider = geom.MakeTrianglesCollider(vs, is)

	return autoCollider
}

func (d *Drawer) FillCircle(dst *ebiten.Image, pos geom.Point, radius float64, clr color.Color) {
	offset := d.applyAnchor(d.Offset.AsVec2().Add(pos.AsVec2()), geom.Size{radius, radius})
	vector.DrawFilledCircle(dst, float32(offset.X), float32(offset.Y), float32(radius), clr, false)
}

func (d *Drawer) FillSquare(dst *ebiten.Image, pos geom.Point, size float64, rotation geom.Radian, bg color.Color) {
	d.FillRectangle(dst, pos, geom.Size{Width: size, Height: size}, rotation, bg)
}

func (d *Drawer) FillSimpleTriangle(dst *ebiten.Image, pos geom.Point, size float64, rotation geom.Radian, bg color.Color) {
	path := d.GetPathForSimpleTriangle(pos, size, rotation)

	vs, is, op := d.preparePathToFill(path, bg)
	d.drawPath(dst, vs, is, op)
}

func (d *Drawer) FillPentagon(dst *ebiten.Image, pos geom.Point, size float64, rotation geom.Radian, bg color.Color) {
	path := d.GetPathForPentagon(pos, size, rotation)

	vs, is, op := d.preparePathToFill(path, bg)
	d.drawPath(dst, vs, is, op)
}

func (d *Drawer) FillStar(dst *ebiten.Image, pos geom.Point, size float64, rotation geom.Radian, bg color.Color) {
	path := d.GetPathForStar(pos, size, rotation)

	vs, is, op := d.preparePathToFill(path, bg)
	d.drawPath(dst, vs, is, op)
}

func (d *Drawer) FillCross(dst *ebiten.Image, pos geom.Point, size float64, rotation geom.Radian, bg color.Color) {
	path := d.GetPathForStar(pos, size, rotation)

	vs, is, op := d.preparePathToFill(path, bg)
	d.drawPath(dst, vs, is, op)
}
